home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2227 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.3 KB

  1. Path: ix.netcom.com!netnews
  2. From: miker3@ix.netcom.com (Mike Rubenstein)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Initalizing variables in a for loop
  5. Date: Tue, 16 Jan 1996 13:03:39 GMT
  6. Organization: Netcom
  7. Message-ID: <30fba161.37516992@nntp.ix.netcom.com>
  8. References: <st95h6e9-1501962022390001@myers1-006.resnet.drexel.edu>
  9. NNTP-Posting-Host: ix-dc6-24.ix.netcom.com
  10. X-NETCOM-Date: Tue Jan 16  5:03:31 AM PST 1996
  11. X-Newsreader: Forte Agent .99c/16.141
  12.  
  13. st95h6e9@dunx1.ocs.drexel.edu (Luke Cassady-Dorion) wrote:
  14.  
  15. |>When initalizing a variable in a for loop as in the example below
  16. does the
  17. |>compiler free up the memory allocated to that variable after the
  18. loop
  19. |>exits, thus making the variable unuseable by other parts of the
  20. function,
  21. |>or its it retined??
  22. |>
  23. |>
  24. |>   for (int i=0; i < some_value, i++)
  25.  
  26. According to the draft, i is local to the loop and is unavailable
  27. after the loop exits.  Many compilers still use an older rule in which
  28. i remains in scope until the end of the enclosing block.
  29.  
  30. Even in the first case, the memory for i may not be released until the
  31. function ends.  Many compilers allocate all auto memory for a function
  32. when it is entered and release it when it exits.  Such compilers
  33. usually will reuse memory for variables local to other inner blocks.
  34.  
  35.  
  36. Michael M Rubenstein
  37.